

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>lightmeter &mdash; Lightmeter v0.0.5 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.0.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="Lightmeter v0.0.5 documentation" href="../index.html" />
    <link rel="up" title="Module code" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../index.html">Lightmeter v0.0.5 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for lightmeter</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/env python</span>
<span class="c"># -*- coding: UTF-8 -*-</span>

<span class="n">VendorID</span><span class="o">=</span><span class="mh">0x04d8</span><span class="p">;</span>                        <span class="c"># Microchip, Inc</span>
<span class="n">ProductID</span><span class="o">=</span><span class="mh">0xfcb7</span><span class="p">;</span>                       <span class="c"># PICDEM FS USB demo app</span>
<span class="n">Configuration</span><span class="o">=</span><span class="mh">0x1</span><span class="p">;</span>                      <span class="c"># USB configuration number</span>
<span class="n">Interface</span><span class="o">=</span><span class="mh">0x0</span><span class="p">;</span>                          <span class="c"># USB interface number</span>
<span class="n">EndpointIn</span><span class="o">=</span><span class="mh">0x81</span><span class="p">;</span>                        <span class="c"># USB endpoint address for input</span>
<span class="n">EndpointOut</span><span class="o">=</span><span class="mh">0x1</span><span class="p">;</span>                        <span class="c"># USB endpoint address for output</span>
<span class="n">Timeout</span><span class="o">=</span><span class="mi">2000</span><span class="p">;</span>                           <span class="c"># Timeout in ms</span>
<span class="n">ReqLen</span><span class="o">=</span><span class="mi">64</span><span class="p">;</span>                              <span class="c"># Request length</span>
<span class="n">Degree</span><span class="o">=</span><span class="s">u&#39;C&#39;</span>                             <span class="c"># Degree Sign</span>
<span class="n">QuestionLight</span> <span class="o">=</span> <span class="s">&#39;L&#39;</span>                     <span class="c"># Request string for light data</span>
<span class="n">QuestionTemp</span> <span class="o">=</span> <span class="s">&#39;T&#39;</span>                      <span class="c"># Request string for temperature data</span>
<span class="n">QuestionID</span> <span class="o">=</span> <span class="s">&#39;i&#39;</span>                      <span class="c"># Request string for sensor id</span>
<span class="n">MaskStatusLight</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s">&#39;10000000&#39;</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>     <span class="c"># Bitmask for light status bit</span>
<span class="n">MaskDataLight</span> <span class="o">=</span>  <span class="nb">int</span><span class="p">(</span><span class="s">&#39;01111111&#39;</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>      <span class="c"># Bitmask for light data bits</span>
<span class="n">MaskStatusTemp</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s">&#39;00000111&#39;</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>      <span class="c"># Bitmask for temp status bits</span>
<span class="n">Sleep</span> <span class="o">=</span> <span class="mf">1.0</span>                             <span class="c"># Sleep time</span>

<span class="n">LightmeterID</span><span class="o">=</span><span class="p">[{</span><span class="s">&quot;VendorID&quot;</span><span class="p">:</span><span class="mh">0x04d8</span><span class="p">,</span><span class="s">&quot;ProductID&quot;</span><span class="p">:</span><span class="mh">0x000c</span><span class="p">,</span><span class="s">&quot;Version&quot;</span><span class="p">:</span><span class="s">&#39;2.3&#39;</span><span class="p">},{</span><span class="s">&quot;VendorID&quot;</span><span class="p">:</span><span class="mh">0x04d8</span><span class="p">,</span><span class="s">&quot;ProductID&quot;</span><span class="p">:</span><span class="mh">0xfcb7</span><span class="p">,</span><span class="s">&quot;Version&quot;</span><span class="p">:</span><span class="s">&#39;2.4&#39;</span><span class="p">}]</span>

<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">io</span>
<span class="kn">from</span> <span class="nn">optparse</span> <span class="kn">import</span> <span class="n">OptionParser</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">usb.core</span>
    
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">print</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">    PyUSB 1.0 library is missing.</span>
<span class="s">    Please install from http://sourceforge.net/projects/pyusb/files/</span>
<span class="s">    &quot;&quot;&quot;</span>
    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="c">#lightmeters = usb.core.find(idVendor=VendorID, idProduct=ProductID,find_all=True)</span>

<span class="c">#for dev in lightmeters:</span>
<span class="c">#    print dev</span>

<div class="viewcode-block" id="lightmeter"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter">[docs]</a><span class="k">class</span> <span class="nc">lightmeter</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Class that representin a lightmeter.&quot;&quot;&quot;</span>
    
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">debug</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">update</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span><span class="n">sid</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="n">filename</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">delimiter</span><span class="o">=</span><span class="s">&#39;,&#39;</span><span class="p">,</span><span class="n">buffering</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>\
                 <span class="n">latitude</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="n">longitude</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="n">stationid</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="n">serialnumber</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="n">verbose</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="o">=</span><span class="n">debug</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="o">=</span><span class="n">update</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">buffering</span><span class="o">=</span><span class="n">buffering</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sid</span> <span class="o">=</span> <span class="n">sid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="o">=</span><span class="n">filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">=</span><span class="n">delimiter</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filehandler</span><span class="o">=</span><span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">latitude</span><span class="o">=</span><span class="n">latitude</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">longitude</span><span class="o">=</span><span class="n">longitude</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stationid</span><span class="o">=</span><span class="n">stationid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">serialnumber</span><span class="o">=</span><span class="n">serialnumber</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dev</span> <span class="o">=</span> <span class="bp">None</span>
        
    <span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Disconnect from lightmeter station.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dev</span> <span class="o">=</span> <span class="bp">None</span>

<div class="viewcode-block" id="lightmeter.connect"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.connect">[docs]</a>    <span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">number</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Connecting to lightmeter&quot;&quot;&quot;</span>
        
        <span class="n">nr</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">lmid</span> <span class="ow">in</span> <span class="n">LightmeterID</span><span class="p">:</span>
            <span class="n">devices</span><span class="o">=</span> <span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">idVendor</span><span class="o">=</span><span class="n">lmid</span><span class="p">[</span><span class="s">&#39;VendorID&#39;</span><span class="p">],</span> <span class="n">idProduct</span><span class="o">=</span><span class="n">lmid</span><span class="p">[</span><span class="s">&#39;ProductID&#39;</span><span class="p">],</span><span class="n">find_all</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
            
            <span class="k">for</span> <span class="n">dev</span> <span class="ow">in</span> <span class="n">devices</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">nr</span> <span class="o">==</span> <span class="n">number</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_connect</span><span class="p">(</span><span class="n">dev</span><span class="p">)</span>
                <span class="n">nr</span> <span class="o">+=</span> <span class="mi">1</span>
        </div>
    <span class="k">def</span> <span class="nf">_connect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">dev</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Connecting to lightmeter by device handler&quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="o">=</span><span class="n">dev</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">filehandler</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">filehandler</span><span class="o">=</span><span class="n">io</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span><span class="s">&#39;wb&#39;</span><span class="p">,</span><span class="n">buffering</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">buffering</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">filehandler</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
               <span class="s">&#39;Date&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span><span class="s">&#39;Time&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span>\
               <span class="s">&#39;StationID&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span>\
               <span class="s">&#39;Sensor&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span>\
               <span class="s">&#39;Latitude&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span><span class="s">&#39;Longitude&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span>\
               <span class="s">&#39;Temperature&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span>\
               <span class="s">&#39;LightRaw&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span><span class="s">&#39;LightCalib&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="o">+</span>\
               <span class="s">&#39;Status&#39;</span><span class="o">+</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span>
           <span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Connecting to lightmeter&quot;</span>
        
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="o">.</span><span class="n">set_configuration</span><span class="p">(</span><span class="n">Configuration</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">serialnumber</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">serialnumber</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">readsnr</span><span class="p">()</span>
            

        <span class="k">except</span> <span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="o">.</span><span class="n">detach_kernel_driver</span><span class="p">(</span><span class="n">Interface</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="o">.</span><span class="n">attach_kernel_driver</span><span class="p">(</span><span class="n">Interface</span><span class="p">)</span>
            <span class="k">except</span> <span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">:</span>
                <span class="k">pass</span>
                
<div class="viewcode-block" id="lightmeter.reset"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.reset">[docs]</a>    <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Resetting USB device&quot;&quot;&quot;</span>
        <span class="n">dev</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dev</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dev</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">while</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="p">:</span>
            <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">Sleep</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_connect</span><span class="p">(</span><span class="n">dev</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="lightmeter.list"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.list">[docs]</a>    <span class="k">def</span> <span class="nf">list</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Listing connected lightmeters.&quot;&quot;&quot;</span>
        
        <span class="k">print</span> <span class="s">&quot;Lightmeters:&quot;</span>
        <span class="n">nr</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">lmid</span> <span class="ow">in</span> <span class="n">LightmeterID</span><span class="p">:</span>
            <span class="n">devices</span><span class="o">=</span> <span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">idVendor</span><span class="o">=</span><span class="n">lmid</span><span class="p">[</span><span class="s">&#39;VendorID&#39;</span><span class="p">],</span> <span class="n">idProduct</span><span class="o">=</span><span class="n">lmid</span><span class="p">[</span><span class="s">&#39;ProductID&#39;</span><span class="p">],</span><span class="n">find_all</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
            
            <span class="k">for</span> <span class="n">dev</span> <span class="ow">in</span> <span class="n">devices</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">nr</span><span class="p">)</span>
                <span class="n">snr</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">readsnr</span><span class="p">()</span>
                <span class="k">print</span> <span class="s">&quot; </span><span class="si">%i</span><span class="s">:</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">nr</span><span class="p">,</span><span class="n">lmid</span><span class="p">[</span><span class="s">&#39;Version&#39;</span><span class="p">],</span><span class="n">snr</span><span class="p">)</span>
                <span class="n">nr</span> <span class="o">+=</span> <span class="mi">1</span>
            </div>
<div class="viewcode-block" id="lightmeter.write"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">buffer</span><span class="p">,</span><span class="n">timeout</span><span class="o">=</span><span class="n">Timeout</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write to USB device&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">EndpointOut</span><span class="p">,</span><span class="nb">buffer</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">timeout</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="lightmeter.read"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.read">[docs]</a>    <span class="k">def</span> <span class="nf">read</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numbytes</span><span class="o">=</span><span class="n">ReqLen</span><span class="p">,</span><span class="n">timeout</span><span class="o">=</span><span class="n">Timeout</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Read from USB device&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">EndpointIn</span><span class="p">,</span><span class="n">numbytes</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">timeout</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="lightmeter.getval"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.getval">[docs]</a>    <span class="k">def</span> <span class="nf">getval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">question</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get value from USB device&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">question</span><span class="p">)</span>    
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
        <span class="k">except</span> <span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;USB IOError&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">getval</span><span class="p">(</span><span class="n">question</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="lightmeter.readsnr"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.readsnr">[docs]</a>    <span class="k">def</span> <span class="nf">readsnr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Read Serial Number&quot;&quot;&quot;</span>
        <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getval</span><span class="p">(</span><span class="n">QuestionID</span><span class="p">)</span>
        <span class="n">snr</span> <span class="o">=</span> <span class="bp">None</span>
        
        <span class="k">if</span> <span class="n">req</span><span class="p">:</span>
            <span class="n">snrlow</span><span class="p">,</span><span class="n">snrhigh</span> <span class="o">=</span> <span class="n">req</span>
            <span class="k">if</span> <span class="n">snrhigh</span> <span class="o">&lt;&gt;</span> <span class="mi">255</span> <span class="ow">and</span> <span class="n">snrlow</span> <span class="o">&lt;&gt;</span> <span class="mi">255</span><span class="p">:</span>
                <span class="n">snr</span> <span class="o">=</span> <span class="n">snrhigh</span><span class="o">*</span><span class="mi">256</span> <span class="o">+</span> <span class="n">snrlow</span>

                <span class="k">if</span> <span class="n">snr</span> <span class="o">&lt;</span> <span class="mi">10000</span><span class="p">:</span>
                    <span class="n">snr</span> <span class="o">+=</span> <span class="mi">910000</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">snr</span> <span class="o">+=</span> <span class="mi">1000000</span>
        
        <span class="k">return</span> <span class="n">snr</span>
        </div>
<div class="viewcode-block" id="lightmeter.readlight"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.readlight">[docs]</a>    <span class="k">def</span> <span class="nf">readlight</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Read light value&quot;&quot;&quot;</span>
        <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getval</span><span class="p">(</span><span class="n">QuestionLight</span><span class="p">)</span> 
        
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">req</span><span class="p">)</span> <span class="o">==</span><span class="mi">3</span> <span class="p">:</span>           
            <span class="n">lightlow</span><span class="p">,</span> <span class="n">lighthigh</span><span class="p">,</span> <span class="n">valrange</span><span class="o">=</span> <span class="n">req</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">req</span><span class="p">)</span> <span class="o">==</span><span class="mi">7</span> <span class="p">:</span> 
            <span class="n">lightlow</span><span class="p">,</span> <span class="n">lighthigh</span><span class="p">,</span> <span class="n">valrange</span><span class="p">,</span> <span class="n">tslmw0low</span><span class="p">,</span> <span class="n">tslmw0high</span><span class="p">,</span> <span class="n">tslmw1low</span><span class="p">,</span> <span class="n">tslmw1high</span> <span class="o">=</span> <span class="n">req</span>
       
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">req</span><span class="p">)</span> <span class="o">==</span><span class="mi">3</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">req</span><span class="p">)</span> <span class="o">==</span><span class="mi">7</span> <span class="p">:</span> 
  
            <span class="n">status</span> <span class="o">=</span> <span class="p">(</span><span class="n">lighthigh</span> <span class="o">&amp;</span> <span class="n">MaskStatusLight</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span>               <span class="c"># Check if status bit == 0</span>
            <span class="n">lightraw</span> <span class="o">=</span> <span class="p">((</span><span class="n">lighthigh</span> <span class="o">&amp;</span> <span class="n">MaskDataLight</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="mi">8</span><span class="p">)</span>  <span class="o">+</span> <span class="n">lightlow</span>
            
            <span class="k">if</span> <span class="n">valrange</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">light</span> <span class="o">=</span> <span class="n">lightraw</span> <span class="o">*</span> <span class="mi">120</span>
            <span class="k">elif</span> <span class="n">valrange</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">light</span> <span class="o">=</span> <span class="n">lightraw</span> <span class="o">*</span> <span class="mi">8</span>
            <span class="k">elif</span> <span class="n">valrange</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                <span class="n">light</span> <span class="o">=</span> <span class="n">lightraw</span> <span class="o">*</span> <span class="mi">4</span>
            <span class="k">elif</span> <span class="n">valrange</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                <span class="n">light</span> <span class="o">=</span> <span class="n">lightraw</span> <span class="o">*</span> <span class="mi">2</span>
            <span class="k">elif</span> <span class="n">valrange</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                <span class="n">light</span> <span class="o">=</span> <span class="n">lightraw</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">light</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">light</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
            <span class="n">status</span> <span class="o">=</span> <span class="bp">False</span>
    
        <span class="k">return</span> <span class="n">light</span><span class="p">,</span><span class="n">status</span>
     </div>
<div class="viewcode-block" id="lightmeter.readtemp"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.readtemp">[docs]</a>    <span class="k">def</span> <span class="nf">readtemp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Read temperature&quot;&quot;&quot;</span>
        <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getval</span><span class="p">(</span><span class="n">QuestionTemp</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">req</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">templow</span><span class="p">,</span> <span class="n">temphigh</span> <span class="o">=</span> <span class="n">req</span>
        
            <span class="n">status</span> <span class="o">=</span> <span class="p">(</span><span class="n">templow</span> <span class="o">&amp;</span> <span class="n">MaskStatusTemp</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span>            <span class="c"># Check if status bit == 0</span>
            <span class="n">tempraw</span> <span class="o">=</span> <span class="p">((</span><span class="n">temphigh</span> <span class="o">&lt;&lt;</span> <span class="mi">8</span><span class="p">)</span>  <span class="o">+</span> <span class="n">templow</span> <span class="p">)</span> <span class="o">&gt;&gt;</span> <span class="mi">3</span>        <span class="c"># Statusbits ausblenden</span>
            <span class="n">temp</span> <span class="o">=</span> <span class="mf">625.0</span> <span class="o">*</span> <span class="n">tempraw</span> <span class="o">/</span> <span class="mf">10000.0</span>                    <span class="c"># Umrechnung von 1/16° zu 1/10°</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">temp</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span> 
            <span class="n">status</span> <span class="o">=</span> <span class="bp">False</span>
        
        <span class="k">return</span> <span class="n">temp</span><span class="p">,</span> <span class="n">status</span>
        </div>
<div class="viewcode-block" id="lightmeter.reader"><a class="viewcode-back" href="../code.html#lightmeter.lightmeter.reader">[docs]</a>    <span class="k">def</span> <span class="nf">reader</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Continously read from lightmeter&quot;&quot;&quot;</span>
        <span class="n">dtupdate</span> <span class="o">=</span>  <span class="n">timedelta</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">)</span>
        <span class="n">dtmes</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span>
        
        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>      
            <span class="n">dtnow</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span>
            <span class="n">dtuncalibrated</span> <span class="o">=</span> <span class="n">dtmes</span> <span class="o">+</span> <span class="n">dtupdate</span>
            <span class="n">dtcalibrated</span> <span class="o">=</span> <span class="n">dtuncalibrated</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">microsecond</span><span class="o">=</span><span class="p">(</span><span class="n">dtuncalibrated</span><span class="o">.</span><span class="n">microsecond</span><span class="p">)</span><span class="o">/</span><span class="mi">100000</span><span class="o">*</span><span class="mi">100000</span><span class="p">)</span>
            <span class="n">dtsleep</span> <span class="o">=</span> <span class="n">dtcalibrated</span> <span class="o">-</span> <span class="n">dtnow</span>
            <span class="n">sleep</span> <span class="o">=</span> <span class="n">dtsleep</span><span class="o">.</span><span class="n">seconds</span><span class="o">+</span><span class="p">(</span><span class="n">dtsleep</span><span class="o">.</span><span class="n">microseconds</span><span class="p">)</span><span class="o">/</span><span class="mf">1000.0</span><span class="o">/</span><span class="mf">1000.0</span>
            <span class="k">if</span> <span class="n">sleep</span> <span class="o">&lt;</span> <span class="mi">61</span><span class="p">:</span>
                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">sleep</span><span class="p">)</span>          
                <span class="n">dtmes</span><span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span>  
            <span class="n">temp</span><span class="p">,</span> <span class="n">tempStatus</span> <span class="o">=</span> <span class="n">lm</span><span class="o">.</span><span class="n">readtemp</span><span class="p">()</span>
            <span class="n">light</span><span class="p">,</span> <span class="n">lightStatus</span> <span class="o">=</span> <span class="n">lm</span><span class="o">.</span><span class="n">readlight</span><span class="p">()</span>
            <span class="n">status</span> <span class="o">=</span> <span class="n">lightStatus</span>
            
            <span class="k">if</span> <span class="n">status</span><span class="p">:</span>
                <span class="n">status</span><span class="o">=</span><span class="s">&#39;OK&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">status</span><span class="o">=</span><span class="s">&#39;ERR&#39;</span>
            
            <span class="n">dtstamp</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span>
            <span class="n">datenow</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%04i</span><span class="s">-</span><span class="si">%02i</span><span class="s">-</span><span class="si">%02i</span><span class="s">&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">dtstamp</span><span class="o">.</span><span class="n">year</span><span class="p">,</span><span class="n">dtstamp</span><span class="o">.</span><span class="n">month</span><span class="p">,</span><span class="n">dtstamp</span><span class="o">.</span><span class="n">day</span><span class="p">)</span>
            <span class="n">timenow</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%02i</span><span class="s">:</span><span class="si">%02i</span><span class="s">:</span><span class="si">%02i</span><span class="s">+</span><span class="si">%04i</span><span class="s">&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">dtmes</span><span class="o">.</span><span class="n">hour</span><span class="p">,</span><span class="n">dtmes</span><span class="o">.</span><span class="n">minute</span><span class="p">,</span><span class="n">dtmes</span><span class="o">.</span><span class="n">second</span><span class="p">,</span><span class="n">dtmes</span><span class="o">.</span><span class="n">microsecond</span><span class="o">/</span><span class="mi">1000</span><span class="p">)</span>
            
            <span class="n">line</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s</span><span class="s">&quot;</span><span class="o">%</span><span class="p">(</span>
                    <span class="n">datenow</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span><span class="n">timenow</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">stationid</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">serialnumber</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">latitude</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">longitude</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span>
                    <span class="n">temp</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span>
                    <span class="n">light</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span>
                    <span class="n">status</span>
                    <span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">filehandler</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">filehandler</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="o">+</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">)</span>
                
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">:</span>
                <span class="k">print</span> <span class="n">line</span>
</div></div>
<div class="viewcode-block" id="main"><a class="viewcode-back" href="../code.html#lightmeter.main">[docs]</a><span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;run lightmeter&quot;&quot;&quot;</span>
    
    <span class="n">parser</span> <span class="o">=</span> <span class="n">OptionParser</span><span class="p">()</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-l&quot;</span><span class="p">,</span><span class="s">&quot;--list&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;list&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;list connected lightmeters&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-d&quot;</span><span class="p">,</span><span class="s">&quot;--debug&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;debug&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;enable debug&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-c&quot;</span><span class="p">,</span><span class="s">&quot;--connect&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;connect&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;connect to lightmeter&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-n&quot;</span><span class="p">,</span><span class="s">&quot;--number&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;number&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;number&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;lightmeter number&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-u&quot;</span><span class="p">,</span><span class="s">&quot;--update&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;update&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;seconds&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;update frequency in seconds [</span><span class="si">%d</span><span class="s">efault]&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-i&quot;</span><span class="p">,</span><span class="s">&quot;--stationid&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;stationid&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;id&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;station id&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-s&quot;</span><span class="p">,</span><span class="s">&quot;--serial-number&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;serialnumber&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;snr&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;serial number&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-f&quot;</span><span class="p">,</span><span class="s">&quot;--file&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;filename&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;file&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;filename for data logging&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-b&quot;</span><span class="p">,</span><span class="s">&quot;--buffering&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;buffering&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;bytes&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;buffer file I/O [</span><span class="si">%d</span><span class="s">efault]&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--delimiter&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;delimiter&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">&#39;,&#39;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;delimiter&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;csv delimiter [</span><span class="si">%d</span><span class="s">efault]&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--lat&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;latitude&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;latitude&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;set latitude&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span> <span class="s">&quot;--lon&quot;</span><span class="p">,</span><span class="n">dest</span><span class="o">=</span><span class="s">&quot;longitude&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;longitude&quot;</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;set longitude&quot;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-v&quot;</span><span class="p">,</span> <span class="s">&quot;--verbose&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">&quot;verbose&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                                      <span class="n">help</span><span class="o">=</span><span class="s">&quot;be verbose&quot;</span><span class="p">)</span>
    <span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>

    <span class="n">lm</span> <span class="o">=</span> <span class="n">lightmeter</span><span class="p">(</span><span class="n">debug</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">debug</span><span class="p">,</span>
                    <span class="n">update</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">update</span><span class="p">),</span>
                    <span class="n">stationid</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">stationid</span><span class="p">,</span>
                    <span class="n">serialnumber</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">serialnumber</span><span class="p">,</span>
                    <span class="n">filename</span><span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span>
                    <span class="n">delimiter</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">delimiter</span><span class="p">,</span>
                    <span class="n">buffering</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">buffering</span><span class="p">,</span>
                    <span class="n">latitude</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">latitude</span><span class="p">,</span>
                    <span class="n">longitude</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">longitude</span><span class="p">,</span>
                    <span class="n">verbose</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">verbose</span>
                    <span class="p">)</span>
                    
    <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">connect</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">filename</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">list</span><span class="p">:</span>
        <span class="n">parser</span><span class="o">.</span><span class="n">print_help</span><span class="p">()</span>
        <span class="nb">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
     
    <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">list</span><span class="p">:</span>
        <span class="n">lm</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
        <span class="nb">exit</span><span class="p">()</span>
        
    <span class="n">lm</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">number</span><span class="p">))</span>
    <span class="n">lm</span><span class="o">.</span><span class="n">reader</span><span class="p">()</span>
           
           </div>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span>
    <span class="n">main</span><span class="p">()</span>
        
        
    
    
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../index.html">Lightmeter v0.0.5 documentation</a> &raquo;</li>
          <li><a href="index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2011, Andreas Trawoeger.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>